import React from 'react';

import Model from '../components/model';
import Button from '../components/button';

import YmtApi from 'YmtApi';

const searchParam = YmtApi.utils.getUrlObj();


let FormDialog = React.createClass({
	getInitialState(){
		return {
			msgTxt:''
		}
	},
	render (){ 
		const { 
			show,
			onHideDialog,
			alertMsg,
			showButtonList=[0],
			openUrl,
			onOpenFormDialog,
			onHideFormDialog,
			onBuyNow,
			onShareHandler,
			showDialogHd,
			onShowRuleDialog,
			resetCountDown,
			params={} }  = this.props;

		const buttonsList = [
			<div key="0" className="btn btn-w-full" 
			     onClick={onHideDialog}>我知道了</div>,
			<div  key="1" className="btn btn-w-full" 
			     onClick={()=>{
			     	openUrl({
			     		url:'/list.html',
			     		title:'砍价团列表'
			     	});
			     }}>算了，去看看其他的</div>,
			<div  key="2" className="btn btn-w-full" 
			     onClick={()=>{
			     	onHideDialog();
			     	onOpenFormDialog();
			     	resetCountDown()
			     }}>换个手机号试试</div>,
			<div  key="3" className="btn btn-w-full" 
			     onClick={onHideDialog}>使用这个手机号重新登录</div>,
			<div  key="4" className="btn btn-w-full" 
			     onClick={()=>{
			     	window.location.href='http://download.app.ymatou.com/index.aspx?from=inapp25';
			     }}>哼! 下载APP，自己去开团</div>,
			<div  key="5" className="btn btn-w-full" 
			      onClick={()=>{
			      	onHideDialog();
			      	onHideFormDialog();
			      }}>使用该手机绑定的微信号重新登录</div>,
			<div  key="6" className="btn btn-w-full" 
			      onClick={()=>{
			      	onShareHandler(params.groupCode)
			      }}>呼朋唤友来参团</div>,
			<div  key="7" className="btn btn-w-full" 
			      onClick={onOpenFormDialog}>我已在此团中</div>,
			<div  key="8" className="btn btn-w-full" 
			      onClick={()=>{
			      	openUrl({
			      		url:'/detail.html?tuanId='+searchParam.tuanId,
			      		title:'砍价团列表'
			      	})
			      }}>我知道了</div>,
			<div  key="9" className="btn btn-w-full" 
			      onClick={onShowRuleDialog}>查看规则</div>
		]

		let buttonHmtl;
		if(showButtonList[0] === -1){
			buttonHmtl = (
				<div className="cols-btn_2">
					<button 
						className="btn pull-left"
						onClick={onHideDialog}>稍后</button>
					<button 
						className="btn pull-left"
						onClick={onBuyNow}>立即购买</button>
				</div>
			)
		}else{
			buttonHmtl = showButtonList.map((i)=>{
				return buttonsList[i];
			});
		}
		
		let dialogHd;

		if(showDialogHd){
			dialogHd = (
				<div className="model-dialog-hd">
					<span className="close-btn pull-right"
						  onClick={()=>{
						  	onHideDialog('alertDialogShow')
						  }}></span>
				</div>
			)
		}

		return (
			<Model show={ show }>
				<div className="model-dialog center alert-dialog">
					<div className="model-content">
						{dialogHd}
						<div className="model-dialog-bd">
							<div className="content" dangerouslySetInnerHTML={{__html:alertMsg}}></div>
						</div>
						<div className="model-dialog-ft">
							{ buttonHmtl }
						</div>
					</div>
				</div>
			</Model>
		)
	}
});

export default FormDialog